package MainDemo;/**
 * @author XuXiaoK
 * @create 2020-01-21 14:00
 */

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import rx.Observable;
import rx.Observer;

/**
 * @Author XiaoKe
 * @Date 2020/1/21 14:00
 * @Description TODO
 */
public class RunTest {

    public static void main(String[] args) throws InterruptedException {
        RunCmmand execute = new RunCmmand("使用execute");
        execute.execute();

        RunCmmand queue = new RunCmmand("使用queue");
        queue.queue();

        RunCmmand toObservable = new RunCmmand("使用toObservable");
        Observable<String> ob = toObservable.toObservable();
        ob.subscribe(new Observer<String>() {
            public void onCompleted() {
                System.out.println("任务完成");
            }

            public void onError(Throwable throwable) {

            }

            public void onNext(String s) {
                System.out.println("任务结果"+s);
            }
        });
        Thread.sleep(100);
    }


    static class RunCmmand extends HystrixCommand<String> {
        String msg;

        public RunCmmand(String msg) {
            super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));
            this.msg = msg;
        }

        protected String run() throws Exception {
            System.out.println(msg);
            return "success";
        }
    }
}
